<template>
  <transition name="slide-fade">
    <div style="height: 100%">
      <img src="../assets/imgs/indexBg1.jpg" alt="">
      <img src="../assets/imgs/front.png" alt="" style="display: none">
      <img src="../assets/imgs/back.png" alt="" style="display: none">
      <el-container>
        <el-header>房间号
          <span style="color: gold">{{room_id}}</span>
          <!--<div class="quitBtn" @click="quit_room()">-->
            <!--◀ &nbsp;离开房间-->
          <!--</div>-->
        </el-header>
        <div class="result_title">
          {{result.message}}
        </div>
        <div class="result_content">

          <div v-for="(player,index) in result.data.out">
            <div v-if="player.identity == 'normal'">
              {{player.nickname}}(平民)被淘汰

            </div>
            <div v-else-if="player.identity == 'white'" style="color:lightgreen">
              {{player.nickname}}(白板)被淘汰
            </div>
            <div v-else="player.identity == 'spy'" style="color:orangered">
              {{player.nickname}}(卧底)被淘汰
            </div>
          </div>
          <div v-for="(player,index) in result.data.win">
            <div v-if="player.identity == 'normal'">
              {{player.nickname}}(平民)

            </div>
            <div v-else-if="player.identity == 'white'" style="color:lightgreen">
              {{player.nickname}}(白板)
            </div>
            <div v-else="player.identity == 'spy'" style="color:orangered">
              {{player.nickname}}(卧底)
            </div>
          </div>
        </div>
        <div class="startBtn">
          <el-button class="el-button el-button--success" @click="toPage('gamehome')">
            再来一局
          </el-button>
        </div>
      </el-container>
    </div>
  </transition>
</template>

<script>
  export default {
    name: 'result',
    data:()=>({
        result:{}
    }),
    created(){
      this.room_id = window.localStorage.getItem('room_id')
      this.player_id = window.localStorage.getItem('player_id')
      this.$axios.post(this.urlList.authUrl + '/api/game/get_ending_info',{
        room_id:this.room_id
      }).then((res)=>{
        this.result = res.data
      })
    },
    methods:{
      quit_room(){
        this.$axios.post(this.urlList.authUrl + '/api/game/quit_room',{
          token:window.localStorage.getItem('token'),
          room_id:this.room_id,
          player_id:this.player_id
        }).then((res)=>{
          if(res.data.error == 200){
            alert('您已经离开了'+ this.room_id +'号房间')
            window.localStorage.removeItem('player_id')
            window.localStorage.removeItem('room_id')
            this.$router.replace({name:'index'})
          }
        })
      },
      toPage (page) {
        this.$axios.post(this.urlList.authUrl + '/api/game/cls_cache',{room_id:this.room_id}).then((res)=>{
          if(res.data.error != 200){
            this.$message(res.data.message)
          }
        })
        this.$router.push({name: page,params:{player_id:this.player_id}})
      },
    },
    destroyed(){

    }
  }
</script>

<style scoped>
  .el-container{
    width: 100%;
    position: absolute;
    top: 0;
  }
  .el-header {
    background:url('../assets/imgs/topBG.jpg') no-repeat;
    background-size:cover;
    background-position:bottom right;
    color: #fff;
    text-align: center;
    line-height: 60px;
  }
  img{
    position: absolute;
    width: 100%;
    height: 100%;
  }
  .quitBtn{
    position: absolute;
    top: 0;
    color:red;
    font-size: 12px;
    margin-left: 10px;
    left: 0;
  }
  .result_title{
    text-align: center;
    font-weight: 700;
    color: gold;
    font-size: 1.2em;
    padding: 10px;
    text-shadow: 0 2px 6px gold;
  }
  .result_content{
    width: 80%;
    margin: auto;
    margin-top: 20px;
    padding: 15px 0;
    line-height: 1.8em;
    border: 1px solid #222;
    border-radius: 10px;
    background: #333;
    text-align: center;
    max-height: 200px;
    overflow: auto;
    color: snow;
  }
  .startBtn{
    width: 100%;

    margin-top: 40px;
    color: #dfe4ed;
    text-align: center;
  }
</style>
